//
//  StatisticsCountCell.swift
//  XingCeHelper
//
//  Created by 申铭 on 2022/11/1.
//

import UIKit

class StatisticsCountCell: BaseTableViewCell {

    @IBOutlet weak var containerView1: UIView!
    @IBOutlet weak var titleLabel1: UILabel!
    @IBOutlet weak var infoLabel1: UILabel!
    @IBOutlet weak var containerView2: UIView!
    @IBOutlet weak var titleLabel2: UILabel!
    @IBOutlet weak var infoLabel2: UILabel!
    @IBOutlet weak var btn2: BaseButton!
    @IBOutlet weak var btn1: BaseButton!
    
    var model: StatisticsCountCellModel? {
        didSet {
            titleLabel1.text = model?.title1
            infoLabel1.text = model?.info1
            
            if let title2 = model?.title2 {
                titleLabel2.text = title2
                infoLabel2.text = model?.info2
            }
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        containerView1.setFillet(cornerRadius: 8)
        containerView2.setFillet(cornerRadius: 8)
        
        selectionStyle = .none
        backgroundColor = .clear
        
        btn1.normalColor = .systemBackground
        btn2.normalColor = .systemBackground
        btn1.highlightedColor = .systemGray5
        btn2.highlightedColor = .systemGray5
        btn1.addTarget(self, action: #selector(self.clickButton(btn:)), for: .touchUpInside)
        btn1.tag = 1
        btn2.addTarget(self, action: #selector(self.clickButton(btn:)), for: .touchUpInside)
        btn2.tag = 2
    }
    
    @objc private func clickButton(btn: UIButton) {
        guard let block = model?.clickBtn else { return }
        if btn.tag == 1 {
            block("\(model?.title1 ?? "1")")
        } else {
            block("\(model?.title2 ?? "2")")
        }
    }
}
